package com.topnav.mc.admin.dao.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.topnav.mc.admin.entity.FencePolygon;
import com.topnav.mc.admin.entity.Permission;
import com.topnav.mc.admin.entity.bean.FencePolygonBean;
import com.topnav.mc.admin.entity.bean.PermissionBean;
import com.topnav.mc.admin.entity.param.FencePolygonParam;
import com.topnav.mc.admin.entity.param.PermissionParam;
import com.topnav.mc.base.mc.McMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 说明：
 * @类名: PermissionMapper
 * <p>
 *
 * </p>
 * @author   kenny
 * @Date	 2022年2月10日上午10:51:53
 */
@Mapper
public interface PermissionMapper extends McMapper<Permission, PermissionBean, PermissionParam> {

	String commSql = " SELECT * FROM mc_permission ${ew.customSqlSegment}";
	@Select(commSql)
	PermissionBean selectInfoOne(@Param(Constants.WRAPPER) Wrapper queryWrapper);

	@Select(commSql)
	List<PermissionBean> selectInfoList(@Param(Constants.WRAPPER) Wrapper queryWrapper);

	@Select(commSql)
	Page<PermissionBean> selectInfoPage(Page<PermissionParam> page, @Param(Constants.WRAPPER) Wrapper queryWrapper);

	/**
	 * 查询所有的权限
	 * @return
	 */
	@Select("SELECT * FROM mc_permission ORDER BY sort_index ASC")
	List<Permission> findAllPermission();

	/**
	 * 根据用户ID查权限
	 * @param userId
	 * @return
	 */
	@Select("SELECT p.* FROM mc_role_permission rp	" +
			" LEFT JOIN mc_permission p ON rp.pm_id = p.id	" +
			" LEFT JOIN mc_user_role ur ON rp.role_id = ur.role_id	" +
			" WHERE ur.user_id = #{userId} ")
	List<Permission> findPermissionByUserId(@Param("userId")Long userId);
}
